package com.zxn.test.ui.blog

import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.wanandroid.model.resultbean.BlogType
import com.zxn.test.R
import com.zxn.test.base.BaseVMFragment
import com.zxn.test.databinding.FragmentBlogBinding
import org.koin.androidx.viewmodel.ext.android.viewModel

class BlogFragment : BaseVMFragment<FragmentBlogBinding>(R.layout.fragment_blog) {

    private val blogViewModel by viewModel<BlogViewModel>()
    private val blogTypeList = mutableListOf<BlogType>()
    override fun initView() {
        view?.let {
            val blogViewPager = it.findViewById<ViewPager2>(R.id.blogViewPager)
            val blogTabLayout = it.findViewById<TabLayout>(R.id.blogTabLayout)

            /*blogViewPager.adapter = object : FragmentStateAdapter(this) {
                override fun getItemCount() = blogTypeList.size

                override fun createFragment(position: Int) = chooseFragment(position)

            }
            TabLayoutMediator(blogTabLayout, blogViewPager) { tab, position ->
                tab.text = blogTypeList[position].name
            }.attach()*/
        }
    }

//    private fun chooseFragment(position: Int): Fragment {
//      return  BlogArticleFragment.newInstance(blogTypeList[position].id)
//    }

    override fun initData() {
        blogViewModel.getBlogType()
    }


    override fun startObserve() {
        /*blogViewModel.blogTypeList.observe(viewLifecycleOwner, Observer {
            it.run {
                blogTypeList.clear()
                blogTypeList.addAll(it)
                blogViewPager.adapter?.notifyDataSetChanged()
            }
        })*/
    }

}